//
//  IntegerValueFormatter.m
//  OneMeeting
//
//  Created by 张衡 on 2019/12/6.
//  Copyright © 2019 www.zhangheng.com. All rights reserved.
//

#import "IntegerValueFormatter.h"
#import <AppKit/AppKit.h>

@implementation IntegerValueFormatter

- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
{
    if([partialString length] == 0) {
        return YES;
    }
    
    if([partialString length] >= 20) {
        return NO;
    }
    
    NSScanner* scanner = [NSScanner scannerWithString:partialString];
    
    
    if(!([scanner scanInt:0] && [scanner isAtEnd])) {
        NSBeep();
        return NO;
    }
    
    
    return YES;
}

@end
